package models

import (
	"time"

	"gorm.io/gorm"
)

type RobotDailyReport struct {
	ID                      string     `gorm:"primaryKey;column:id;type:varchar(20);not null" json:"id"`
	MerchantID              *string    `gorm:"index:idx_createdDate_merchantID_robotName,priority:2,type:btree;column:merchant_id;type:bigint;not null;default:0;comment:商户ID" json:"merchant_id"`
	MerchantName            *string    `gorm:"-" json:"merchant_name"`
	RobotName               *string    `gorm:"index:idx_createdDate_merchantID_robotName,priority:3,type:btree;uniqueIndex:idx_createdDate_robotName,priority:2;column:robot_name;type:varchar(50);not null;default:'';comment:机器名称" json:"robot_name"`
	CreatedDate             *time.Time `gorm:"index:idx_createdDate_merchantID_robotName,priority:1,type:btree;uniqueIndex:idx_createdDate_robotName,priority:1;column:created_date;type:date;comment:日期" json:"-"`
	CreatedDateFormated     *int64     `gorm:"-" json:"created_date"`
	ProvinceID              *string    `gorm:"column:province_id;type:bigint;not null;default:0;comment:省份ID" json:"province_id"`
	CityID                  *string    `gorm:"column:city_id;type:bigint;not null;default:0;comment:城市ID" json:"city_id"`
	DistrictID              *string    `gorm:"column:district_id;type:bigint;not null;default:0;comment:区县ID" json:"district_id"`
	LocationID              *string    `gorm:"column:location_id;type:bigint;not null;default:0;comment:位置ID" json:"location_id"`
	GoodsInventory          *int64     `gorm:"column:goods_inventory;type:bigint;not null;default:0;comment:截止昨天机器当前库存" json:"goods_inventory,omitempty"`
	GoodsMaxInventory       *int64     `gorm:"column:goods_max_inventory;type:bigint;not null;default:0;comment:截止昨天机器的允许最大库存" json:"goods_max_inventory,omitempty"`
	GMV                     *float64   `gorm:"column:gmv;type:decimal(10,2);not null;default:0.00;comment:GMV" json:"gmv,omitempty"`
	PaymentAmount           *float64   `gorm:"column:payment_amount;type:decimal(10,2);not null;default:0.00;comment:实付金额" json:"payment_amount,omitempty"`
	TransactionAmount       *float64   `gorm:"column:transaction_amount;type:decimal(10,2);not null;default:0.00;comment:交易金额" json:"transaction_amount,omitempty"`
	DiscountAmount          *float64   `gorm:"column:discount_amount;type:decimal(10,2);not null;default:0.00;comment:优惠金额" json:"discount_amount,omitempty"`
	RefundAmount            *float64   `gorm:"column:refund_amount;type:decimal(10,2);not null;default:0.00;comment:退款金额" json:"refund_amount,omitempty"`
	GiveAmount              *float64   `gorm:"column:give_amount;type:decimal(10,2);not null;default:0.00;comment:抽奖赠送" json:"give_amount,omitempty"`
	TotalOrder              *int64     `gorm:"column:total_order;type:int(10);not null;default:0;comment:创单笔数" json:"total_order,omitempty"`
	TotalPaidOrder          *int64     `gorm:"column:total_paid_order;type:int(10);not null;default:0;comment:支付笔数" json:"total_paid_order,omitempty"`
	TotalNotPaidOrder       *int64     `gorm:"column:total_not_paid_order;type:int(10);not null;default:0;comment:未支付笔数" json:"total_not_paid_order,omitempty"`
	TotalRefundOrder        *int64     `gorm:"column:total_refund_order;type:int(10);not null;default:0;comment:退款笔数" json:"total_refund_order,omitempty"`
	TotalPaidUser           *int64     `gorm:"column:total_paid_user;type:int(10);not null;default:0;comment:支付人数" json:"total_paid_user,omitempty"`
	TotalScreenClick        *int64     `gorm:"column:total_screen_click;type:int(10);not null;default:0;comment:屏幕点击量" json:"total_screen_click,omitempty"`
	TotalGoodsClick         *int64     `gorm:"column:total_goods_click;type:int(10);not null;default:0;comment:商品点击量" json:"total_goods_click,omitempty"`
	Facecount               *float64   `gorm:"column:facecount;type:decimal(10,2);not null;default:0.00;comment:曝光量" json:"facecount,omitempty"`
	FacecountFront          *float64   `gorm:"column:facecount_front;type:decimal(10,2);not null;default:0.00;comment:曝光量前" json:"facecount_front,omitempty"`
	FacecountLeft           *float64   `gorm:"column:facecount_left;type:decimal(10,2);not null;default:0.00;comment:曝光量左" json:"facecount_left,omitempty"`
	FacecountRight          *float64   `gorm:"column:facecount_right;type:decimal(10,2);not null;default:0.00;comment:曝光量右" json:"facecount_right,omitempty"`
	FacecountBack           *float64   `gorm:"column:facecount_back;type:decimal(10,2);not null;default:0.00;comment:曝光量后" json:"facecount_back,omitempty"`
	Starecount              *int64     `gorm:"column:starecount;type:int(10);not null;default:0;comment:凝视" json:"starecount,omitempty"`
	StarecountFront         *int64     `gorm:"column:starecount_front;type:int(10);not null;default:0;comment:前凝视" json:"starecount_front,omitempty"`
	StarecountLeft          *int64     `gorm:"column:starecount_left;type:int(10);not null;default:0;comment:左凝视" json:"starecount_left,omitempty"`
	StarecountRight         *int64     `gorm:"column:starecount_right;type:int(10);not null;default:0;comment:右凝视" json:"starecount_right,omitempty"`
	StarecountBack          *int64     `gorm:"column:starecount_back;type:int(10);not null;default:0;comment:后凝视" json:"starecount_back,omitempty"`
	TotalOperationDuration  *int64     `gorm:"column:total_operation_duration;type:int(10);not null;default:0;comment:运营时长，单位毫秒" json:"total_operation_duration,omitempty"`
	TotalChargingDuration   *int64     `gorm:"column:total_charging_duration;type:int(10);not null;default:0;comment:充电时长，单位秒" json:"total_charging_duration,omitempty"`
	TotalIdleDuration       *int64     `gorm:"column:total_idle_duration;type:int(10);not null;default:0;comment:闲置时长, 单位秒" json:"total_idle_duration,omitempty"`
	TotalTaskDuration       *int64     `gorm:"column:total_task_duration;type:int(10);not null;default:0;comment:任务时长，单位毫秒" json:"total_task_duration,omitempty"`
	TotalToTaskDuration     *int64     `gorm:"column:total_to_task_duration;type:int(10);not null;default:0;comment:出门时长，单位毫秒" json:"total_to_task_duration,omitempty"`
	TotalToChargingDuration *int64     `gorm:"column:total_to_charging_duration;type:int(10);not null;default:0;comment:回充时长，单位毫秒" json:"total_to_charging_duration,omitempty"`
	TotalFaultDuration      *int64     `gorm:"column:total_fault_duration;type:int(10);not null;default:0;comment:异常时长，单位秒" json:"total_fault_duration,omitempty"`
	TotalTaskOdometer       *int64     `gorm:"column:total_task_odometer;type:int(10);not null;default:0;comment:任务里程, 单位厘米" json:"total_task_odometer,omitempty"`
	TotalTaskRunCount       *int64     `gorm:"column:total_task_run_count;type:int(10);not null;default:0;comment:任务次数" json:"total_task_run_count,omitempty"`
	OpeningFlag             *string    `gorm:"column:opening_flag;type:varchar(50);default:0;comment:新城新店标识" json:"opening_flag"`
	OpeningTime             *string    `gorm:"column:opening_time;type:varchar(50);default:0;comment:新城新店开业时间" json:"opening_time"`
	GoodsClickRatio         *float64   `gorm:"-" json:"goods_click_ratio"`  // 商品点击率
	PaidRatio               *float64   `gorm:"-" json:"paid_ratio"`         // 支付率
	CreateOrderRatio        *float64   `gorm:"-" json:"create_order_ratio"` // 创单率
	RefundRatio             *float64   `gorm:"-" json:"refund_ratio"`       // 退款率
	RobotCount              *int64     `gorm:"->" json:"robot_count"`       // 设备数 只读
	Province                *string    `gorm:"-" json:"province"`
	City                    *string    `gorm:"-" json:"city"`
	District                *string    `gorm:"-" json:"district"`
	Location                *string    `gorm:"-" json:"location"`
	CreatedAt               int64      `gorm:"column:created_at;autoCreateTime;type:int;size:64;comment:创建时间" json:"created_at"`
	UpdatedAt               int64      `gorm:"column:updated_at;autoUpdateTime;type:int;size:64;comment:更新时间" json:"updated_at"`
}

func (m *RobotDailyReport) AfterFind(tx *gorm.DB) (err error) {
	if m.CreatedDate != nil {
		if !time.Time(*m.CreatedDate).IsZero() {
			createdDate := m.CreatedDate.Unix()
			m.CreatedDateFormated = &createdDate
		}
	}
	return
}
func (m RobotDailyReport) TableName() string {
	return "robot_daily_report"
}

// 模式自动注册
func init() {
	Models = append(Models, &RobotDailyReport{})
}
